#include "ircclientstarter.h"

IrcClientStarter::IrcClientStarter(ConnectionData conf, HttpServer* web, QObject *parent) :
    QObject(parent),
    m_ircClient(nullptr),
    m_webUi(web),
    m_conf(conf)
{}

void IrcClientStarter::RunInit()
{
    m_ircClient = new IrcClient(m_conf, this);

    QObject::connect (m_ircClient, SIGNAL(userOnline(QString, QString, QStringList)),
                          m_webUi, SLOT(ircUsersOnline(QString, QString, QStringList)),
                      Qt::QueuedConnection);

    QObject::connect (m_ircClient, SIGNAL(myNickname(QString, QString)),
                          m_webUi, SLOT(ircBotNick(QString, QString)),
                      Qt::QueuedConnection);

    QObject::connect (m_ircClient, SIGNAL(topicChanged(QString, QString, QString)),
                          m_webUi, SLOT(ircChannelTopic(QString, QString, QString)),
                      Qt::QueuedConnection);

    QObject::connect (m_ircClient, SIGNAL(myOnline(QString, quint8)),
                          m_webUi, SLOT(ircServerOnline(QString, quint8)),
                      Qt::QueuedConnection);

    QObject::connect (m_ircClient, SIGNAL(startInfo(QString, QStringList)),
                          m_webUi, SLOT(ircBotFirstInfo(QString, QStringList)),
                      Qt::QueuedConnection);

    QObject::connect (m_ircClient, SIGNAL(newMessage(QString, QString, QString, QString)),
                          m_webUi, SLOT(ircMessageCache(QString, QString, QString, QString)),
                      Qt::QueuedConnection);

    m_ircClient->connectToServer();
}
